///Use LineChart in fcharts instead of charts_flutter
import 'package:fcharts/fcharts.dart';
import 'package:flutter/material.dart';

var data1 = [
  ['04-12\n16:00', '78'],
  ['04-13\n16:00', '75'],
  ['04-14\n16:00', '100'],
  ['04-15\n16:00', '25'],
  ['04-16\n16:00', '5'],
];

var data2 = [
  ['04-16\n16:00', 25],
  ['04-16\n04:00', 55],
  ['04-15\n16:00', 99],
  ['04-15\n04:00', 75],
  ['04-14\n16:00', 75],
];

var data3 = [
  ['04-16\n16:00', 5],
  ['04-16\n08:00', 25],
  ['04-16\n00:00', 100],
  ['04-15\n16:00', 75],
  ['04-15\n08:00', 78],
];

var data4 = [
  ['04-16\n16:00', 25],
  ['04-16\n10:00', 55],
  ['04-16\n04:00', 99],
  ['04-15\n22:00', 75],
  ['04-15\n16:00', 75],
];

var data5 = [
  ['04-16\n16:00', 5],
  ['04-16\n11:12', 25],
  ['04-16\n06:24', 100],
  ['04-16\n01:46', 75],
  ['04-15\n20:48', 78],
];

var data = [
  data1,
  data2,
  data3,
  data4,
  data5,
];

void main() {
  runApp(MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData.fallback(),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Chart Demo'),
        ),
        body: PointsLineChart(),
      )
  ));
}

class PointsLineChart extends StatefulWidget {
  @override
  PointsLineChartState createState() => PointsLineChartState();
}

class PointsLineChartState extends State<PointsLineChart> {

  int index = 0;
//  List<String> tsdata = data[0];

  Widget chartWidget() {

    var chart = new LineChart(
      lines: [
        new Line<List<String>, String, String>(
          data: data1,
          xFn: (datum) => datum[0],
          yFn: (datum) => datum[1], )
      ],
      chartPadding: EdgeInsets.fromLTRB(30.0, 10.0, 10.0, 30.0),
    );

    return Container(
      height: 350,
      child: new Card(child: GestureDetector(
        onScaleUpdate: (ScaleUpdateDetails scaleDetails) {
          debugPrint("scale details:" + scaleDetails.toString());
        },
        child: chart,
      )),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Row(
          children: [
            new Expanded(
              child: chartWidget(),
            ),
          ],
        ),
        SizedBox(
          height: 35.0,
        ),
        Text('Current level ${index + 1}',
          style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700)),
        SizedBox(
          height: 35.0,
        ),
        RaisedButton(
          onPressed: () {
//            setState(() {
//              index = index + 1;
//              if (index > 4) index = 4;
//              debugPrint("current index: $index");
//              tsdata = data[index];
//            });
          },
          child: Text('Zoom in'),
        ),
        RaisedButton(
          onPressed: () {
//            setState(() {
//              index = index - 1;
//              if (index < 0) index = 0;
//              debugPrint("current index: $index");
//              tsdata = data[index];
//            });
          },
          child: Text('Zoom out'),
        ),
      ],
    );
  }
}
